package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.Finance;
import com.ruoyi.finance.service.IFinanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 财务管理Controller
 * 
 * @author wxl
 * @date 2023-11-11
 */
@RestController
@RequestMapping("/finance/finance")
public class FinanceController extends BaseController
{
    @Autowired
    private IFinanceService financeService;

    /**
     * 查询财务管理列表
     */
    @PreAuthorize("@ss.hasPermi('finance:finance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Finance finance)
    {
        startPage();
        List<Finance> list = financeService.selectFinanceList(finance);
        return getDataTable(list);
    }

    /**
     * 导出财务管理列表
     */
    @PreAuthorize("@ss.hasPermi('finance:finance:export')")
    @Log(title = "财务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Finance finance)
    {
        List<Finance> list = financeService.selectFinanceList(finance);
        ExcelUtil<Finance> util = new ExcelUtil<Finance>(Finance.class);
        util.exportExcel(response, list, "财务管理数据");
    }

    /**
     * 获取财务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:finance:query')")
    @GetMapping(value = "/{financeId}")
    public AjaxResult getInfo(@PathVariable("financeId") Long financeId)
    {
        return success(financeService.selectFinanceByFinanceId(financeId));
    }

    /**
     * 新增财务管理
     */
    @PreAuthorize("@ss.hasPermi('finance:finance:add')")
    @Log(title = "财务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Finance finance)
    {
        return toAjax(financeService.insertFinance(finance));
    }

    /**
     * 修改财务管理
     */
    @PreAuthorize("@ss.hasPermi('finance:finance:edit')")
    @Log(title = "财务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Finance finance)
    {
        return toAjax(financeService.updateFinance(finance));
    }

    /**
     * 删除财务管理
     */
    @PreAuthorize("@ss.hasPermi('finance:finance:remove')")
    @Log(title = "财务管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{financeIds}")
    public AjaxResult remove(@PathVariable Long[] financeIds)
    {
        return toAjax(financeService.deleteFinanceByFinanceIds(financeIds));
    }
}
